package tjs.study.mini.springbootstartsmini.boot.web;

import lombok.SneakyThrows;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import java.util.Set;

/**
 * 对标以下类
 * {@link org.springframework.web.SpringServletContainerInitializer} @HandlesTypes(WebApplicationInitializer.class)
 *
 * @author nicky
 * @date 2021/9/7 下午12:21
 */
// 将WebApplicationInitializer的所有实现类，传入this.onStartup的webAppInitializerClasses形参
//@HandlesTypes(WebApplicationInitializer.class)
public class SpringServletContainerInitializer implements ServletContainerInitializer {

    private ServletContextInitializer[] initializers;

    public SpringServletContainerInitializer(ServletContextInitializer[] initializers) {
        this.initializers = initializers;
    }

    @SneakyThrows
    @Override
    public void onStartup(Set<Class<?>> webAppInitializerClasses, ServletContext servletContext) {
        for (ServletContextInitializer initializer : initializers) {
            initializer.onStartup(servletContext);
        }
    }
}
